Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoongArch: gas: add support using variable for li.w/d #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calring
Copy link

@Calring Calring commented Aug 12, 2022

   Macro instruction li.w/d support using variable
    like ".equ var, 123    li.w/d resgister, var".

gas/
* config/loongarch-parse.y
* config/tc-loongarch.c

    Add two testcases.

gas/
* testsuite/gas/loongarch/li.d
* testsuite/gas/loongarch/li.s
* testsuite/gas/loongarch/li2.d
* testsuite/gas/loongarch/li2.s

@@ -318,6 +335,7 @@ offsetT imm;

primary_expression
: INTEGER {emit_const ($1);}
| IDENTIFIER {emit_const_var ($1);}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judging from this, isn't the change applicable to more insns than li.[wd] alone?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're exactly right. Let me fix this again to only works for li.w./d

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're exactly right. Let me fix this again to only works for li.w./d

No no no. In its current form it's way more ergonomic. I for example would be very surprised to find out that variable substitution only works for li.[wd], I'd curse loudly for the anti-feature.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean you'd simply write more test cases to showcase the usage with a wide variety of insns, and reword the commit message. Just don't restrict to li only.

Copy link
Author

@Calring Calring Aug 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we know, the li.[wd] is a macro instruction used to load immediate. li.w can load 32 bits immediate, and li.d can load 64 bits immediate. If a programmer need to load immediate, li.[wd] is completely competent. If other instructions also support, for programmer who don't know instructions immediate bits width, It is easy to make mistakes . For eaxmple, addi.[wd] rd, rj, var can only load 12 bits width immediate, if var bits width exceeds 12, it will be not work. So support li.[wd] is enough, that's my thought.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in that case you may want to improve the error message so the user is hinted towards li.[wd]. Inconsistency is not good for learners, despite your good intention. It is bound to cause confusion, believe me...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I got you, you're right. I will add more testcases for other instructions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this feature of other ARCHs like x86, their behavior is really the same as you said!!!That's cool!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this feature of other ARCHs like x86, their behavior is really the same as you said!!!That's cool!

Told you. ;-)

        Instructions that can load immediate support using constant
        variable like ".equ var, 123    li.w/d resgister, var".

gas/
        * config/loongarch-parse.y
        * config/tc-loongarch.c

        Add two testcases.One is a program using constant variable,
        another test almost all instructions that can load immediate.

gas/
        * testsuite/gas/loongarch/li.d
        * testsuite/gas/loongarch/li.s
        * testsuite/gas/loongarch/imm_ins.d
        * testsuite/gas/loongarch/imm_ins.s
@Calring
Copy link
Author

Calring commented Aug 15, 2022

LoongArch: gas: add support using constant variable in instructions.

    Instructions that can load immediate support using constant
    variable like ".equ var, 123    li.w/d resgister, var".

gas/
* config/loongarch-parse.y
* config/tc-loongarch.c

    Add two testcases.One is a program using constant variable,
    another test almost all instructions that can load immediate.

gas/
* testsuite/gas/loongarch/li.d
* testsuite/gas/loongarch/li.s
* testsuite/gas/loongarch/imm_ins.d
* testsuite/gas/loongarch/imm_ins.s

@Calring Calring mentioned this pull request Aug 15, 2022
as_bad("illegal operand: %s", op);
top->value.X_op = O_constant;
top->value.X_add_number = ep.X_add_number;
top->type = BFD_RELOC_LARCH_SOP_PUSH_ABSOLUTE;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the resulting object file will have this reloc record? Because we may be working with lld/mold that cannot process stack-based relocations, in which case we actually want to substitute the value in, as if the user had written the concrete value in the respective slot. Otherwise the approach is mostly okay.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once it is recognized as a constant, it will discarded this reloc in subsequent processing, and obviously object file will have not this reloc record.

Copy link

@xen0n xen0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants